package com.yb.livewykt.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.yb.livewykt.R
import com.yb.livewykt.bean.LiveAction

class LiveActionRecyclerAdapter(val context: Context,val dataList:List<LiveAction>) : RecyclerView.Adapter<LiveActionRecyclerAdapter.ActionViewHolder>() {


   private var itemClickListener:(LiveAction) -> Unit = {}

    fun setOnItemClickListener(click:(LiveAction) -> Unit){
        this.itemClickListener = click
    }


    class ActionViewHolder(itemView:View) :RecyclerView.ViewHolder(itemView){
        val icon:ImageView = itemView.findViewById(R.id.icon)
        val name:TextView = itemView.findViewById(R.id.name)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ActionViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.adapter_live_action_layout,parent,false)
        return ActionViewHolder(view)
    }

    override fun onBindViewHolder(holder: ActionViewHolder, position: Int) {
        Glide.with(context).load(dataList[position].actionIcon).into(holder.icon)
        holder.name.text = context.resources.getString(dataList[position].actionName)
        holder.itemView.setOnClickListener {
            itemClickListener(dataList[position])
        }
    }

    override fun getItemCount(): Int = dataList.size
}